package yunhe.servlet;

import yunhe.service.BoardServers;
import yunhe.service.impl.BoardServersImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@SuppressWarnings("serial")
public class AddBoard extends HttpServlet {
	
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		resp.setCharacterEncoding("utf-8");
		String bname=req.getParameter("bname");
		BoardServers bs=new BoardServersImpl();
		int re=bs.addBoard(new String[]{bname});
		HttpSession session=req.getSession();
		if(re>0){
			session.setAttribute("addBoardSucc", true);
		}
		else{
			session.setAttribute("addBoardSucc", false);
		}
		resp.sendRedirect("GetBoard?flag=EditBoard");
	}
	
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}
}
